Repository navigation
fix(daemon-client): bound the judge-again loop on a clock, not a wait count - #4899
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 89925aa. The verdict and the full list are in the summary comment.
…ait count `ENSURE_ATTEMPTS` divided the teardown grace by the judge-again delay, so a contended `ensureDaemon` always ran 300 judgements. A wait count understates what the call can spend: the work inside a judgement is not waited for, so a state directory another process keeps replacing held the call for 300 judgements plus what each judgement cost. The budget is now one teardown grace of elapsed time on the monotonic clock the package's other budgets use, each wait clamped to what is left; one grace of waits backstops the deadline, which a clock that stops cannot pass. `daemon-client-ensure-explicit-lifecycle.test.ts` mocked `sleep` and still ran those 300 iterations of real work, which is what pushed it past the test timeout on a busy host. It now moves the budget clock, as the startup-budget and drain suites move theirs, so the grace passes in five judgements. Production timing is unchanged, and the waits are still asked for at the production cadence, so the budget assertion pins it.
89925aa to
5423fc0
Compare
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
|
The code in 5423fc0 is ready. CI is green with 22 checks and none failing, and there are no conflicts. The earlier inline thread on the wall-clock deadline is fixed at this head and can be resolved: #4899 (comment). Not blocking, and fine to take or leave: the deadline is checked only after each judgement returns, so one in-flight judgement can run past it (see https://github.com/callstack/agent-device/blob/5423fc0/packages/daemon-client/src/daemon-client-ensure.ts#L69); the comment at line 62 says the budgets are "like the transport and lifecycle budgets" although the transport, liveness and startup budgets use Date.now, so it could name the specific budgets or drop the comparison; and maxWaits guards against a clock that stops, which performance.now cannot do, so it could go unless it is a deliberate guard against a frozen clock in tests. Not verified here: the test file and repo gates were not run, the 20-run timing table in the PR body (measured one commit earlier, as the author states) was not reproduced, and the Date.now-versus-mtime reasoning for the spy seam was not checked against inspectProcessLock. |
Summary
ensureDaemonre-judged a contended state directory a fixed 300 times:ENSURE_ATTEMPTSdivided the teardown grace by the 250 ms judge-again delay. A wait count understates the call, because the work inside a judgement is not waited for: the base held it for 300 judgements plus what each one cost. The budget is now one teardown grace of elapsed time on the monotonic clock this package's other budgets use, each wait clamped to what is left, with a wait ceiling backstopping the deadline so a clock that stops cannot spin. Production timing is unchanged. No new seam: the budget cases move the clock inside this suite, as the startup and drain suites already do. No timeout raised, no assertion dropped, no waiver.Before / after
No observable change. A contended
ensureDaemonstill reportsdaemon-lifecycle-contendedafter the same waits; only how the budget is measured differs.Validation
Head
5423fc00f7, baseda3d3601bb. The file run 20 times in a row at each, per-run duration:The two contended cases, worst run of each set: 329 ms base, 211 ms head.
Both pass on an idle host: the flake needs CPU starvation, and the base loop is the side that grows under load.
pnpm check:affected --runpasses at head; the durations above were measured at89925aa275, the same change before it read the monotonic clock. CI owns coverage and device lanes. No device-facing change.🤖 Generated with Claude Code